package com.swingolf.web;

import com.swingolf.dao.TournamentDAO;
import com.swingolf.model.Tournament;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;

public class TournamentConverter implements Converter<String, Tournament> {

  @Autowired TournamentDAO tournamentDAO;

  public Tournament convert(String s) {
    if (!StringUtils.hasText(s)) {
      return null;
    }
    Long id = Long.parseLong(s);
    return tournamentDAO.findById(id);
  }
}
